package main

/*
Singleton is a creational design pattern,
which ensures that only one object of its kind exists
and provides a single point of access to it for any other code.
*/
import (
	"fmt"
	"sync"
	"time"
)

type single struct{}

var instance *single
var once sync.Once

func getInstance(wg *sync.WaitGroup) *single {
	defer wg.Done()
	once.Do(func() {
		fmt.Println("初始化了")
		instance = &single{}
		time.Sleep(time.Second)
	})
	return instance
}
